package com.example.task1.ui.AllService.YouthStation;

import android.content.Intent;
import android.os.Bundle;
import android.view.MenuItem;
import android.widget.TextView;

import androidx.annotation.NonNull;
import androidx.appcompat.app.ActionBar;
import androidx.appcompat.app.AppCompatActivity;

import com.example.task1.R;
import com.example.task1.application.MyApplication;
import com.example.task1.bean.StationDetailsBean;
import com.example.task1.http.Api;
import com.example.task1.util.ApiResp;
import com.example.task1.util.CallBack;
import com.youth.banner.Banner;

import java.util.List;

import retrofit2.Call;

public class StationDetailsActivity extends AppCompatActivity {

    private int id;
    private Banner banner;
    private TextView tvAddress;
    private TextView tvTime,tvPhone;
    private TextView tvBody;
    private TextView tvGirl;
    private TextView tvIntroduce;
    private TextView tvInternalFacilities;
    private TextView tvSurroundingFacilities;
    private TextView tvSpecialService;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_station_details);
        Intent intent = getIntent();
        id = intent.getIntExtra("id", 0);
        ActionBar supportActionBar = getSupportActionBar();
        supportActionBar.setTitle("驿站详情");
        supportActionBar.setDisplayHomeAsUpEnabled(true);
        initData();
        initView();
    }

    @Override
    public boolean onOptionsItemSelected(@NonNull MenuItem item) {
        if (item.getItemId() == android.R.id.home) {
            finish();
        }
        return super.onOptionsItemSelected(item);
    }

    private void initData() {
        Call<ApiResp> apiRespCall = Api.api().get(MyApplication.TOKEN,"/prod-api/api/youth-inn/youth-inn/" + id);
        Api.send(apiRespCall, StationDetailsBean.class, new CallBack<StationDetailsBean>() {
            @Override
            public void success(StationDetailsBean data) {
                StationDetailsBean.DataDTO rows = data.getData();
                MyApplication.banner(banner,rows.getImageUrlList());
                tvAddress.setText("地址："+rows.getAddress());
                tvBody.setText("剩余男床："+rows.getBedsCountBoy());
                tvGirl.setText("剩余女床："+rows.getBedsCountGirl());
                tvInternalFacilities.setText("内部服务："+rows.getInternalFacilities());
                tvIntroduce.setText("公寓介绍："+rows.getIntroduce());
                tvSpecialService.setText("特色服务："+rows.getSpecialService());
                tvSurroundingFacilities.setText("周边配套："+rows.getSurroundingFacilities());
                tvTime.setText("接待营业时间："+rows.getWorkTime());
                tvPhone.setText("联系电话："+rows.getPhone());
            }

            @Override
            public void error(String msg) {

            }
        });
    }

    private void initView() {
        banner = (Banner) findViewById(R.id.banner);
        tvAddress = (TextView) findViewById(R.id.tv_address);
        tvTime = (TextView) findViewById(R.id.tv_time);
        tvBody = (TextView) findViewById(R.id.tv_body);
        tvGirl = (TextView) findViewById(R.id.tv_girl);
        tvIntroduce = (TextView) findViewById(R.id.tv_introduce);
        tvInternalFacilities = (TextView) findViewById(R.id.tv_internalFacilities);
        tvSurroundingFacilities = (TextView) findViewById(R.id.tv_surroundingFacilities);
        tvSpecialService = (TextView) findViewById(R.id.tv_specialService);
        tvPhone = (TextView) findViewById(R.id.tv_phone);
    }
}